//
//  trivial examples of loop syntax
//

object loops
  procs
    def foo
      int x, y, z

      x       :=  0
      y       :=  0
      z       :=  0

      loop
        pre
          int i
          i     :=  0
        end
        body
          x   +=  i
          
          if i > 10 then finish
          i   +=  1
        end
      end

      loop
        pre
          int i
          i     :=  0
        end
        body
          y   +=  i

          if i > 10 then done

          i   +=  1
        end
        done
          x   :=  ( 2 * y )
        end
      end

      loop
        pre
          int i
          i     :=  0
        end
        body
          z   +=  i

          if z >= y then break
          if z >= x then break
          if i > 9 then done

          i   +=  1
        end
        broken
          z   :=  0
        end
        done
          x   :=  ( 2 * z )
          y   :=  ( 3 * z )
        end
      end

      loop
        pre
          int             i
          pointer< int >  data
          
          i   :=  0
          data.alloc( 20 )
        end
        body
          if z < 0 then break
          data[ i ]       :=  z + i

          i               :=  i + 1
          if i >= 20 then done
        end
        broken
          x   :=  0
        end
        done
          x   :=  1
        end
        post
          data.free()
        end
      end

    end
  end
end
